import { useState } from "react";

export default function ToDoListAdd({addTodo}) {
  const [tststr, setTststr] = useState("");

  const onSubmit = (e) => {
    e.preventDefault();
    if (tststr.trim() !== "") {
      console.log(tststr);
      addTodo(tststr);
      setTststr("");
    }
  };
  return (
    <>
      <form onSubmit={onSubmit}>
        <input
          type="text"
          value={tststr}
          placeholder="Add a task"
          onChange={(e) => setTststr(e.target.value)}
        />
        <button type="submit">新建事项</button>
      </form>
    </>
  );
}
